// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "MotionSubtitlesLayerBase.h"
#include "TextInfos.h"
#include "MotionSubtitlesStaticTextLayer.generated.h"


UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class MOTIONSUBTITLES_API UMotionSubtitlesStaticTextLayer : public UMotionSubtitlesLayerBase
{
	GENERATED_BODY()

public:

	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category=MotionSubtitles)
	FTextLayoutInfo TextLayoutInfo;
	
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category=MotionSubtitles)
	TArray<UStaticMesh*> TextMeshes;

	UPROPERTY(VisibleInstanceOnly)
	TArray<TObjectPtr<UStaticMeshComponent>> TextPlanes;

	UPROPERTY(VisibleAnywhere)
	TObjectPtr<USceneComponent> TextMeshRoot;

	TArray<FVector> TextOriginLocations;
	TArray<FVector> TextOriginScales;

public:
	UMotionSubtitlesStaticTextLayer();

	virtual void Init(const FUint32Vector2& ViewSize) override;

	UFUNCTION(BlueprintCallable)
	virtual void Show(const FSubtitleParams& Params) override;

	UFUNCTION(BlueprintCallable)
	virtual void Hide() override;

	virtual void Exit() override;

public:
	virtual void DoScale(const EAnimTarget AnimTarget,const int32 ElementId,const float Value) override;
	virtual void DoTranslate(const EAnimTarget AnimTarget, const int32 ElementId,const FVector Value) override;
	virtual void DoFade(const EAnimTarget AnimTarget, const int32 ElementId,const float Value) override;
	virtual void CaptureStatus() override;
	virtual int32 ElementCount() override;
private:

	bool GenerateTextMesh(UStaticMesh* StaticMesh,UStaticMeshComponent*& StaticMeshComponent);

	void LayoutText(TArray<TObjectPtr<UStaticMeshComponent>>& Planes,const FTextLayoutInfo& LayoutInfo);
};
